package com.yywq.service.impl;

import com.yywq.error.BusinessException;
import com.yywq.error.EnumBusinessError;
import com.yywq.mapper.GoodPictureMapper;
import com.yywq.service.GoodPictureService;
import com.yywq.utils.MyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @author: 吴磊
 * @program: yywq
 * @create: 2021-03-20 22:25
 */
@Service
public class GoodPictureServiceImpl implements GoodPictureService {

    @Autowired
    private GoodPictureMapper goodPictureMapper;

    @Override
    public int insertGoodsPicture(String gid, String picPath) {
        if (StringUtils.isEmpty(gid)) {
            throw new BusinessException(EnumBusinessError.PARAMETER_INVALID_ERROR, "商品ID不能为空");
        }
        if (StringUtils.isEmpty(picPath)) {
            throw new BusinessException(EnumBusinessError.PARAMETER_INVALID_ERROR, "商品图片地址不合法");
        }
        String id = MyUtil.getUUID();
        int i = goodPictureMapper.insertGoodsPic(id, gid, picPath);
        return i;
    }
}
